<?php
/**
 * 陈杰  18323491246
 */

namespace App\Models\Api;

use App\Models\BaseModel;
use Illuminate\Support\Facades\Cache;

class ExtendUserModel extends BaseModel
{
    public $table = 'extend_user';

    public static function get_by_uid(int $uid)
    {
        Cache::forget('user_uid_' . $uid);
        $data = Cache::remember('user_uid_' . $uid, 6000, function () use ($uid) {
            $data = self::where('uid', $uid)->first();
            if (!isset($data))
                return false;
            $data = $data->toArray();
            return $data;
        });
        return $data;
    }

    public static function get_group(int $uid)
    {
        $data = self::get_by_uid($uid);
        if (!$data)
            self::dieError('没有加入任何群组');
        $data = explode(',', $data['group']);
        return $data;
    }
}
